<?php
namespace app\index\controller;

use PHPMailer\Mail;
use app\index\model\Cate;
use app\index\model\Question;
use app\index\model\Sign;
use arr\Arr;
use think\Controller;
use think\Db;

class Index extends Common
{

    public function test()
    {
        $res = Mail::send('6955044@qq.com','测试8888','测试内容8888');

        var_dump($res);
    }
    public function index()
    {
    	$topData = Db::name('question')
		->alias('t1')
		->field('t1.*,t2.nickname,t2.face,t3.cate_name')
		->join('user t2','t1.user_id = t2.user_id')
        ->join('cate t3','t1.cate_id = t3.cate_id')
		->where('t1.is_top','1')
		->select();

    	$cates = Cate::all();

    	$where = [];

    	input('cate_id') && $where['t1.cate_id'] = input('cate_id');

    	if(input('type') && input('type')=='1'){
    		$where['t1.status'] = "0";
    	}

    	if(input('type') && input('type')=='2'){
    		$where['t1.status'] = "1";
    	}

    	if(input('type') && input('type')=='3'){
    		$where['t1.is_good'] = "1";
    	}

    	$allData = Db::name('question')
		->alias('t1')
		->field('t1.*,t2.nickname,t2.face,t3.cate_name')
		->join('user t2','t1.user_id = t2.user_id')
        ->join('cate t3','t1.cate_id = t3.cate_id')
        ->where($where)
        ->order('t1.create_time desc')
		->paginate(2);

		$hotReply = Question::order('reply_num desc')->limit(10)->select();

		$sql = "select count(*) num,t1.user_id,t2.nickname,t2.face from fly_reply t1 INNER JOIN fly_user t2 on t1.user_id=t2.user_id where t1.create_time>".strtotime("-7 days")." and t1.create_time<".time()." GROUP BY t1.user_id";

		$weekHot = Db::query($sql);

        $sign = (new Sign)->get_sign_info();


        $this->assign('sign',$sign);

        $this->assign('hotReply',$hotReply);
		$this->assign('title',"专业的老司机交流社区");
		$this->assign('weekHot',$weekHot);
    	$this->assign('cates',$cates);
    	$this->assign('topData',$topData);
    	$this->assign('allData',$allData);
        return $this->fetch();
    }
}
